package com.kma.summer2012.client.view.manager;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.*;
import com.kma.summer2012.client.presenters.manager.AssignPagePresenter;
import com.kma.summer2012.client.styles.style2.Recources;
import com.kma.summer2012.client.view.viewmap.ViewMap;

import java.util.Date;

public class AssignPageView extends Composite implements AssignPagePresenter.Display {


    interface AssignPageViewUiBinder extends UiBinder<Widget, AssignPageView> {
    }

    private static AssignPageViewUiBinder ourUiBinder = GWT.create(AssignPageViewUiBinder.class);

    @UiField
    Button cancelButton;
    @UiField
    Button assignButton;
    @UiField
    ListBox listOfUsers;
    @UiField
    ListBox listOfTimeBegin;
    @UiField
    VerticalPanel panel;
    @UiField
    Grid table;
    @UiField
    Label labelDt;
    @UiField
    Label labelT;
    @UiField
    Label labelWork;
    @UiField
    Label labelComment;

    @Override
    public void setRequest(String text) {
        request.setText(text);
    }

    @UiField
    Label request;

    @Override
    public ViewMap getViewMap() {
        return viewMap;
    }

    ViewMap viewMap = new ViewMap();


    public AssignPageView() {
        HTMLPanel rootElement = (HTMLPanel) ourUiBinder.createAndBindUi(this);
        assignButton.addStyleName(Recources.INSTANCE.styles().Caption());
        cancelButton.addStyleName(Recources.INSTANCE.styles().Caption());
        request.setStyleName(Recources.INSTANCE.styles().lable());
        assignButton.setEnabled(false);
        initWidget(rootElement);
        rootElement.add(viewMap);
        rootElement.add(panel);
        rootElement.add(listOfUsers);
        rootElement.add(listOfTimeBegin);
        rootElement.add(assignButton);
        rootElement.add(cancelButton);
    }

    @Override
    public Button getAssignButton() {
        return assignButton;
    }

    @Override
    public Button getCancelButton() {
        return cancelButton;
    }

    @Override
    public String getUser() {
        return listOfUsers.getValue(listOfUsers.getSelectedIndex());
    }


    @Override
    public String getAssignTimeBegin() {
        return listOfTimeBegin.getValue(listOfTimeBegin.getSelectedIndex());
    }


    @Override
    public void backButtonVisible(Boolean visible) {
        this.viewMap.getBackButton().setVisible(visible);
    }

    @Override
    public ListBox getListOfUsers() {
        return listOfUsers;
    }

    @Override
    public ListBox getListOfTimeBegin() {
        return listOfTimeBegin;
    }

    @Override
    public void setLabelComment(String comment) {
        labelComment.setText(comment);
    }

    @Override
    public void setLabelDt(String dt) {
        labelDt.setText(dt);
    }

    @Override
    public void setLabelT(String time) {
        labelT.setText(time);
    }

    @Override
    public void setLabelWork(String work) {
        labelWork.setText(work);
    }

    @Override
    public void changeDateOnCalendar(Date date) {
        viewMap.getCalendar().setValue(date);
    }

    @Override
    public void makeListOfTimeBegin() {
        listOfTimeBegin.addItem("Assign time");
        listOfTimeBegin.addItem("9:00");
        listOfTimeBegin.addItem("10:00");
        listOfTimeBegin.addItem("11:00");
        listOfTimeBegin.addItem("12:00");
        listOfTimeBegin.addItem("13:00");
        listOfTimeBegin.addItem("14:00");
        listOfTimeBegin.addItem("15:00");
        listOfTimeBegin.addItem("16:00");
        listOfTimeBegin.addItem("17:00");
    }


    public Widget asWidget() {
        return this;
    }
}